************************************************
***Title: seasonal_trends_pollen_by_region.do
***Creators: Joelle Abramowitz, Shooshan Danagoulian, and Owen Fleming*
***Notes: This file produces a visualization of the seasonality of pollen measurements by locality for each Census region.

*For questions, contact
*Owen Fleming
*hg3490@wayne.edu
************************************************


**********SETUP
use data/for_analysis, clear

*merge region onto the data
replace statename = strproper(statename)
merge m:1 statename using data/other/census_regions
drop if _merge==2
drop _merge
replace regionname = "South" if statename == "District Of Columbia"


**********PRODUCE VISUALIZATION
*South
preserve
keep if regionname=="South"
keep if county_measurement == county
collapse (mean) pollen, by(week)
gen county = 0
save data/total_averages_south, replace
restore

preserve
keep if regionname=="South"
keep if county_measurement == county
collapse (mean) pollen, by(county week)
append using data/total_averages_south
erase data/total_averages_south.dta
sort county week
label variable pollen "Weekly Average of Pollen (pcm)"

line pollen week if county==10003, lcolor(gs12) || line pollen week if county==13067, lcolor(gs12) || line pollen week if county==21111, lcolor(gs12) || line pollen week if county==24005, lcolor(gs12) || line pollen week if county==24031, lcolor(gs12) || line pollen week if county==37119, lcolor(gs12) || line pollen week if county==40109, lcolor(gs12) || line pollen week if county==40143, lcolor(gs12) || line pollen week if county==45045, lcolor(gs12) || line  pollen week if county==0, lcolor(red) lwidth(medthick) legend(order(10 "All south counties")) ylabel(0 1500 3000 4500) xlabel(2 "Jan" 10.66 "Mar" 19.33 "May" 28 "Jul" 36.66 "Sept" 45.33 "Nov")  title("South") ytitle("") xtitle("") leg(off) graphregion(color(white)) 
graph save results/south, replace
restore

*West
preserve
keep if regionname=="West"
keep if county_measurement == county
collapse (mean) pollen, by(week)
gen county = 0
save data/total_averages_west, replace
restore

preserve
keep if regionname=="West"
keep if county_measurement == county
collapse (mean) pollen, by(county week)
append using data/total_averages_west
erase data/total_averages_west.dta
sort county week
label variable pollen "Weekly Average of Pollen (pcm)"

line pollen week if county==6001, lcolor(gs12) || line pollen week if county==6085, lcolor(gs12) || line pollen week if county==8041, lcolor(gs12) || line pollen week if county==41039, lcolor(gs12) || line pollen week if county==49035, lcolor(gs12) || line pollen week if county==53033, lcolor(gs12) || line  pollen week if county==0, lcolor(red) lwidth(medthick) legend(order(10 "All south counties")) ylabel(0 1500 3000 4500) xlabel(2 "Jan" 10.66 "Mar" 19.33 "May" 28 "Jul" 36.66 "Sept" 45.33 "Nov")  title("West") ytitle("") xtitle("") leg(off) graphregion(color(white)) 
graph save results/west, replace
restore

*Midwest
preserve
keep if regionname=="Midwest"
keep if county_measurement == county
collapse (mean) pollen, by(week)
gen county = 0
save data/total_averages_midwest, replace
restore

preserve
keep if regionname=="Midwest"
keep if county_measurement == county
collapse (mean) pollen, by(county week)
append using data/total_averages_midwest
erase data/total_averages_midwest.dta
sort county week
label variable pollen "Weekly Average of Pollen (pcm)"

line pollen week if county==17031, lcolor(gs12) || line pollen week if county==26099, lcolor(gs12) || line pollen week if county==29095, lcolor(gs12) || line pollen week if county==29510, lcolor(gs12) || line pollen week if county==31153, lcolor(gs12) || line pollen week if county==39113, lcolor(gs12) || line pollen week if county==55063, lcolor(gs12) || line  pollen week if county==0, lcolor(red) lwidth(medthick) legend(order(10 "All south counties")) ylabel(0 1500 3000 4500) xlabel(2 "Jan" 10.66 "Mar" 19.33 "May" 28 "Jul" 36.66 "Sept" 45.33 "Nov")  title("Midwest") ytitle("") xtitle("") leg(off) graphregion(color(white)) 
graph save results/midwest, replace
restore

*Northeast
preserve
keep if regionname=="Northeast"
keep if county_measurement == county
collapse (mean) pollen, by(week)
gen county = 0
save data/total_averages_northeast, replace
restore

preserve
keep if regionname=="Northeast"
keep if county_measurement == county
collapse (mean) pollen, by(county week)
append using data/total_averages_northeast
erase data/total_averages_northeast.dta
sort county week
label variable pollen "Weekly Average of Pollen (pcm)"

line pollen week if county==9009, lcolor(gs12) || line pollen week if county==36009, lcolor(gs12) || line pollen week if county==36055, lcolor(gs12) || line pollen week if county==36061, lcolor(gs12) || line pollen week if county==42049, lcolor(gs12) || line pollen week if county==42133, lcolor(gs12) || line  pollen week if county==0, lcolor(red) lwidth(medthick) legend(order(10 "All south counties")) ylabel(0 1500 3000 4500) xlabel(2 "Jan" 10.66 "Mar" 19.33 "May" 28 "Jul" 36.66 "Sept" 45.33 "Nov")  title("Northeast") ytitle("") xtitle("") leg(off) graphregion(color(white)) 
graph save results/northeast, replace
restore


**********EXPORT
gr combine results/northeast.gph results/midwest.gph results/south.gph results/west.gph, ycommon 
graph export results/seasonal_trends_pollen_by_region.png, replace

